package routers

import (
	"github.com/gin-gonic/gin"
	"yak.admin/src/middleware"
	adminrouter "yak.admin/src/module/backend/admin"
	adminctrl "yak.admin/src/module/backend/admin/controller"
	hnyjrouter "yak.admin/src/module/backend/hnyj"
)

func AdminRouter(router *gin.Engine) *gin.Engine {
	group := router.Group("/")
	group.Use(middleware.AuthRequired())
	{
		adminrouter.Routers(group)
		hnyjrouter.Routers(group)
	}
	router.NoMethod(auth404)
	router.NoRoute(auth404)
	router.GET("/login", func(c *gin.Context) {
		c.Set("Page", "layui/auth/login.html")
	})
	router.POST("/login", adminctrl.Login)
	return router
}

func auth404(c *gin.Context) {
	c.Set("Page", middleware.Page{Title: "错误404", Linker: "/", Tpl: "layui/error/404.tpl"})
}
